package com.qiudaozhang.loveblog.entity;

import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Set;

/**
 * 文章标签实体
 * @author 邱道长
 * 2019/11/13
 */
@Entity
@Setter
@Getter
public class Tag implements Serializable {
    private static final long serialVersionUID = -7035139676178206939L;
    @Id
    @GenericGenerator(strategy = "increment",name = "increment")
    @GeneratedValue(generator = "increment")
    private Long id;

    @Column(nullable = false,unique = true)// 非空约束，不能重复。
    private String name;

    @ManyToMany
    @JoinTable(name = "article_tag",
            joinColumns = {@JoinColumn(name = "tag_id")},
            inverseJoinColumns = {@JoinColumn(name = "article_id")}
    )
    private Set<Article> articles;


    @Override
    public String toString() {
        return "Tag{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }
}
